# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=mini_httpd
pkgver=1.30
pkgrel=5
pkgdesc="Small forking webserver with ssl and ipv6 support"
url="http://www.acme.com/software/mini_httpd/"
arch="all"
license="BSD-2-Clause"
pkgusers="minihttpd"
pkggroups="www-data"
# no tests/check provided by upstream
options="!check"
makedepends="openssl-dev>3"
subpackages="$pkgname-doc $pkgname-openrc"
install="$pkgname.pre-install"
source="http://www.acme.com/software/mini_httpd/mini_httpd-$pkgver.tar.gz
	$pkgname.conf
	$pkgname.initd
	$pkgname.logrotate
	cgi.patch
	implicit.patch
	"
# secfixes:
#   1.30-r0:
#     - CVE-2018-18778
#   1.29-r0:
#     - CVE-2017-17663

build() {
	make CFLAGS="$CFLAGS -DUSE_SSL" \
		LDFLAGS="$LDFLAGS" \
		SSL_LIBS="-lssl -lcrypto"
}

package() {
	# does not respect DESTDIR
	make install \
		BINDIR="$pkgdir"/usr/sbin \
		MANDIR="$pkgdir"/usr/share/man

	mkdir -p "$pkgdir"/usr/bin \
		"$pkgdir"/var/log/$pkgname

	# rename sbin/htpasswd to bin/mini_htpasswd
	mv "$pkgdir"/usr/sbin/htpasswd "$pkgdir"/usr/bin/mini_htpasswd
	mv "$pkgdir"/usr/share/man/man1/htpasswd.1 \
		"$pkgdir"/usr/share/man/man1/mini_htpasswd.1

	install -Dm644 "$srcdir"/$pkgname.conf "$pkgdir"/etc/$pkgname/$pkgname.conf
	install -Dm755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -Dm644 "$srcdir"/$pkgname.logrotate "$pkgdir"/etc/logrotate.d/$pkgname

	install -dm755 -g $pkggroups "$pkgdir"/var/www/localhost/htdocs
}

sha512sums="
c7464bbd6f9b18ad15f662978ca68fab7db1eea5247d2598134869f098c273b745c7bb0ef9a2841acefb94a369937111858aa84028ed08e9b07d9c6fc257a04c  mini_httpd-1.30.tar.gz
1e6ef2da61c82ff5e8bb79058c188954d72c69e9d25abdd9bca51f3122aac8729bcfd6e53ae7ee40807b9250698f2cde13dad51ffed962aa07004c7f456f9cb3  mini_httpd.conf
9daa9052609136a461c912ee2b64829abf2c4c626553a12a3d45c2158be4ed0749126b5ea594fed02a6a4779d7869a073070c259ac28ca19171a168fcbb0632c  mini_httpd.initd
701c8d393963836267289cba7352caaf61925c6a7e4903f0d418245415b214e17dcab3497697dd5c9ab80f3f71c9cb5dbcc0a3706bc6be25b6031da000ee0ef0  mini_httpd.logrotate
ee521382044d0a67791bde53ca8d69f4716b2cb0227f5cc936501b46dffd2f2c2b609f9a151cc3d5b0fd7da48a38bbe7a201335a8accc7f7fa29683bbdc9ba34  cgi.patch
910a0d89fc0e9003c115aceccb93037af48bab5237930fbe58f43c1e686013b2ec96668650536315b7ba5ac4e2d138d013b9c9ce842bb7a5c30351d372987b13  implicit.patch
"
